﻿using Kingdee.BOS.Core.DynamicForm.PlugIn;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.ServiceHelper;
using Kingdee.BOS.Util;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LiMinCRMPlugin
{
    /// <summary>
    /// 收款单保存插件
    /// </summary>
    /// <remarks>
    /// 功能：收款单保存插件获取往来单位编码。
    /// 创建人：wzx
    /// 创建日期：2024.7.10
    /// 修改信息（1）：修改人，修改日期，修改内容
    /// </remarks>
    /// 
    [Description("收款单保存插件获取往来单位编码")]
    [HotUpdate]
    public class ReceiptSaveOperation : AbstractOperationServicePlugIn
    {
        //OnPreparePropertys 数据加载前，确保需要的属性被加载
        public override void OnPreparePropertys(PreparePropertysEventArgs e)
        {
            base.OnPreparePropertys(e);
            //编码
            e.FieldKeys.Add("FBillNo");

            //往来单位
            e.FieldKeys.Add("FCONTACTUNIT");

        }
        /// <summary>
        /// 事务结束后事件
        /// </summary>
        /// <param name="e"></param>
        public override void EndOperationTransaction(EndOperationTransactionArgs e)
        {
            base.EndOperationTransaction(e);

            //读取全部的单据,for循环,转换成DynamicObject类型
            foreach (DynamicObject entity in e.DataEntitys)
            {
                string FID = Convert.ToString(entity["Id"]);//内码                      
                string Number = entity["BillNo"].ToString();//编码
                DynamicObject CONTACTUNIT = entity["CONTACTUNIT"] as DynamicObject;//往来单位
                string CONTACTUNITNo = Convert.ToString(CONTACTUNIT["Number"]);
                string UpPe = string.Format(@"/*dialect*/  update T_AR_RECEIVEBILL set F_QLTK_CONTACTUNITNo='{0}' where FID='{1}'", CONTACTUNITNo, FID);
                DBServiceHelper.Execute(this.Context, UpPe);
            }
        }
    }
}
